package com.group3.hospital.controller;/*
 *@author 时崎
 * 2022/01/02
 */

import com.group3.hospital.bean.User;
import com.group3.hospital.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class PersonalController {
    @Resource
    private UserService userService;
    //展示个人中心画面
    @RequestMapping("/personalUi")
    public String personalUi(){
        return "person_center";
    }
    //个人中心修改个人信息
    @RequestMapping("/updateUser")
    public String updateUser(@RequestParam("username") String username, @RequestParam("userTel")String userTel, @RequestParam("userPassword")String userPassword
                             , @RequestParam("userId") Integer userId, HttpSession session){
        User user = null;
        try {
            user = userService.queryById(userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        user.setUsername(username);
        user.setUserTel(Long.valueOf(userTel));
        user.setUserPassword(userPassword);
        try {
            userService.update(user);
            session.setAttribute("user",user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "redirect:/mainUi";
    }
}
